from django import forms

from gideon.service.starlabs import GideonModelForm
from gideon.forms.widgets import DateTimePickerInput
from supergirl.models import ClassList, School, Course, UserInfo


class ClassListModelForm(GideonModelForm):
    school = forms.ModelChoiceField(
        label="校区",
        widget=forms.widgets.Select(),
        required=True,
        queryset=School.objects.all(),
    )
    course = forms.ModelChoiceField(
        label="课程名称",
        widget=forms.widgets.Select(),
        required=True,
        queryset=Course.objects.all(),
    )
    semester = forms.IntegerField(
        label="班级(期)",
        widget=forms.widgets.Input(),
        required=True,
    )
    price = forms.IntegerField(
        label="学费",
        widget=forms.widgets.Input(),
        required=True,
    )
    start_date = forms.DateField(
        label="开班日期",
        widget=DateTimePickerInput(),
        required=True,
    )
    graduate_date = forms.DateField(
        label="结业日期",
        widget=DateTimePickerInput(),
        required=True,
    )
    class_teacher = forms.ModelChoiceField(
        label="班主任",
        widget=forms.widgets.Select(),
        required=True,
        queryset=UserInfo.objects.filter(depart__name="教质部"),
    )
    tech_teachers = forms.ModelMultipleChoiceField(
        label="任课老师",
        widget=forms.widgets.SelectMultiple(),
        required=True,
        queryset=UserInfo.objects.filter(depart__name__contains="教学部"),
    )
    memo = forms.CharField(
        required=False,
        widget=forms.widgets.TextInput(attrs={'placeholder': '说明'}),
        strip=True,
        label="说明",
    )

    class Meta:
        model = ClassList
        fields = ["school", "course", "semester", "price", "start_date", "graduate_date", "class_teacher",
                  "tech_teachers", "memo", ]
